﻿namespace _198轮转数组
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int[] ints = Solution.Rotate(new int[] { 1, 2, 3, 4, 5, 6, 7 }, 9);
        }
    }


    public class Solution
    {
        /// <summary>
        /// 开辟一个新的数组，将原数组中的元素依次复制到新数组中  时间复杂度O(n) 控件复杂度O(n)
        /// </summary>
        /// <param name="nums"></param>
        /// <param name="k"></param>
        /// <returns></returns>
        public static int[] Rotate(int[] nums, int k)
        {
            int n = nums.Length;
            int[] newArray = new int[n];
            for (int i = 0; i < n; ++i)
            {
                newArray[(i + k) % n] = nums[i];
            }
            Array.Copy(newArray, 0, nums, 0, n);
            return newArray;
        }
    }
}